import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const user = ref({
    username: '',
    email: '',
    id: null
  })

  const isLoggedIn = ref(false)

  const setUser = (userData) => {
    user.value = userData
    isLoggedIn.value = true
  }

  const clearUser = () => {
    user.value = {
      username: '',
      email: '',
      id: null
    }
    isLoggedIn.value = false
  }

  const updateUser = (updates) => {
    user.value = { ...user.value, ...updates }
  }

  return {
    user,
    isLoggedIn,
    setUser,
    clearUser,
    updateUser
  }
})